package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/nursingLevel")
@RestController
@Api(tags = "护理等级")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;
    @ApiOperation("查询所有护理等级")
    @GetMapping("/listAll")
    public ResponseResult listAll(){
        List<NursingLevelVo> list =nursingLevelService.listAll();
        return ResponseResult.success(list);
    }
    @ApiOperation("分页查询护理等级")
    @GetMapping("listByPage")
    public ResponseResult listByPage(
            @ApiParam(value = "护理计划名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "护理计划状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        PageResponse<NursingLevelVo> nursingLevelVoPageInfo  =nursingLevelService.search(name,status,pageNum,pageSize);
        return ResponseResult.success(nursingLevelVoPageInfo);
    }

    @ApiOperation("新增护理等级")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.insert(nursingLevelDto);
        return ResponseResult.success();
    }

    @ApiOperation("根据id查询")
    @GetMapping("/{id}")
    public ResponseResult getNursingLevelById(@PathVariable Long id){
        NursingLevelVo nursingLevelVo = nursingLevelService.getNursingLevelById(id);
        return ResponseResult.success(nursingLevelVo);
    }

    @ApiOperation("修改护理等级")
    @PutMapping("/update")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.update(nursingLevelDto);
        return ResponseResult.success();
    }

    /**
     * 删除
     */

    @ApiOperation("删除护理等级")
    @DeleteMapping("/delete/{id}")
    public ResponseResult delete(@PathVariable Long id){
        nursingLevelService.delete(id);
        return ResponseResult.success();
    }

    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status){
        nursingLevelService.updateStatus(id,status);
        return ResponseResult.success();
    }
}
